package cn.gjxblog.core.captcha;

import cn.gjxblog.core.captcha.img.DefaultImgCaptchaGenerator;
import cn.gjxblog.core.captcha.sms.DefaultSmsSender;
import cn.gjxblog.core.captcha.sms.SmsSender;
import cn.gjxblog.core.properties.SecurityProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/1/17 9:43
 */
@Configuration
public class CaptchaBeanConfig {

    @Resource
    private SecurityProperties securityProperties;

    @Bean
    @ConditionalOnMissingBean(SmsSender.class)
    public SmsSender smsSender(){
        return new DefaultSmsSender();
    }

    @Bean
    @ConditionalOnMissingBean(name = "imgCaptchaGenerator")
    public CaptchaGenerator imgCaptchaGenerator(){
        DefaultImgCaptchaGenerator defaultCaptchaGenerator = new DefaultImgCaptchaGenerator();
        defaultCaptchaGenerator.setSecurityProperties(securityProperties);
        return defaultCaptchaGenerator;
    }
}
